home *** CD-ROM | disk | FTP | other *** search
/ Click Press Kit / Click Press Kit.iso / pc / main.dxr / Internal_131_Soft Edge Wipe.ls < prev    next >
Encoding:
Text File  |  2006-05-31  |  9.8 KB  |  188 lines

  1. property appearWhen, softWipeDuration, direction, softWipeWidth, spriteNum, mySprite, myStartFrame, myEndFrame, myOriginalMember, myOriginalImage, myOriginalAlpha, myTransitionMember, mySoftEdge, myTransitionMask, myAlphaMask
  2.  
  3. on beginSprite me
  4.   mySprite = sprite(spriteNum)
  5.   myOriginalMember = mySprite.member
  6.   myOriginalAlpha = image(myOriginalMember.width, myOriginalMember.height, 8, #grayscale)
  7.   myOriginalAlpha.fill(0, 0, myOriginalMember.width, myOriginalMember.height, rgb(0, 0, 0))
  8.   myOriginalImage = image(myOriginalMember.width, myOriginalMember.height, 32)
  9.   case myOriginalMember.type of
  10.     #bitmap:
  11.       myOriginalImage = myOriginalMember.image
  12.       case myOriginalMember.depth of
  13.         32:
  14.           if myOriginalMember.useAlpha then
  15.             myOriginalAlpha = myOriginalMember.image.extractAlpha()
  16.           end if
  17.       end case
  18.     #text, #vectorShape, #flash:
  19.       if myOriginalMember.type = #text then
  20.         mySprite.rect = mySprite.rect
  21.       end if
  22.       myOriginalAlpha = myOriginalMember.image.extractAlpha()
  23.       if mySprite.ink = 0 then
  24.         case myOriginalMember.type of
  25.           #text, #flash:
  26.             myOriginalImage.fill(myOriginalImage.rect, myOriginalMember.bgColor)
  27.           #vectorShape:
  28.             myOriginalImage.fill(myOriginalImage.rect, myOriginalMember.backgroundColor)
  29.         end case
  30.         myOriginalImage.copyPixels(myOriginalMember.image, myOriginalMember.rect, myOriginalImage.rect, [#maskImage: myOriginalAlpha])
  31.         myOriginalAlpha.fill(myOriginalAlpha.rect, rgb(0, 0, 0))
  32.       else
  33.         myOriginalImage = myOriginalMember.image
  34.       end if
  35.   end case
  36.   myAlphaMask = image(myOriginalMember.width, myOriginalMember.height, 8, 0, #grayscale)
  37.   myAlphaMask.fill(0, 0, myOriginalMember.width, myOriginalMember.height, rgb(255, 255, 255))
  38.   case appearWhen of
  39.     "beginning of sprite":
  40.       myStartFrame = mySprite.startFrame
  41.       myEndFrame = myStartFrame + softWipeDuration - 1
  42.     "end of sprite":
  43.       myEndFrame = mySprite.endFrame
  44.       myStartFrame = myEndFrame - softWipeDuration + 1
  45.   end case
  46.   myTransitionMember = new(#bitmap, castLib(mySprite.castLibNum))
  47.   myTransitionMember.image = image(myOriginalMember.width, myOriginalMember.height, 32, 8)
  48.   myTransitionMember.image.copyPixels(myOriginalImage, myOriginalMember.rect, myOriginalMember.rect)
  49.   myTransitionMember.regPoint = myOriginalMember.regPoint
  50.   myTransitionMember.useAlpha = 1
  51.   mySoftEdge = softWipeWidth
  52.   case direction of
  53.     "left to right", "right to left":
  54.       myTransitionMask = me.makeSharpBoxLR((myTransitionMember.width * 2) + mySoftEdge, myTransitionMember.height)
  55.       myTransitionMask.copyPixels(me.makeBlendBoxLR(mySoftEdge, myTransitionMember.height), rect(myTransitionMember.width, 0, myTransitionMember.width + mySoftEdge, myTransitionMember.height), rect(0, 0, mySoftEdge, myTransitionMember.height))
  56.       if ((appearWhen = "beginning of sprite") and (direction = "right to left")) or ((appearWhen = "end of sprite") and (direction = "left to right")) then
  57.         myTransitionMask.copyPixels(myTransitionMask, [point(myTransitionMask.width, 0), point(0, 0), point(0, myTransitionMask.height), point(myTransitionMask.width, myTransitionMask.height)], myTransitionMask.rect)
  58.       end if
  59.     "top to bottom", "bottom to top":
  60.       myTransitionMask = me.makeSharpBoxTB(myTransitionMember.width, (myTransitionMember.height * 2) + mySoftEdge)
  61.       myTransitionMask.copyPixels(me.makeBlendBoxLR(mySoftEdge, myTransitionMember.width), [point(0, myTransitionMember.height + mySoftEdge), point(0, myTransitionMember.height), point(myTransitionMember.width, myTransitionMember.height), point(myTransitionMember.width, myTransitionMember.height + mySoftEdge)], rect(0, 0, mySoftEdge, myTransitionMember.width))
  62.       if ((appearWhen = "end of sprite") and (direction = "bottom to top")) or ((appearWhen = "beginning of sprite") and (direction = "top to bottom")) then
  63.         myTempAlpha = image(myTransitionMember.width, (myTransitionMember.height * 2) + mySoftEdge, 8, 0, #grayscale)
  64.         myTempAlpha = duplicate(myTransitionMask)
  65.         myTransitionMask.copyPixels(myTempAlpha, [point(myTransitionMask.width, myTransitionMask.height), point(0, myTransitionMask.height), point(0, 0), point(myTransitionMask.width, 0)], myTransitionMask.rect)
  66.       end if
  67.   end case
  68. end
  69.  
  70. on endSprite me
  71.   mySprite.member = myOriginalMember
  72.   erase(myTransitionMember)
  73. end
  74.  
  75. on prepareFrame me
  76.   if (the frame >= myStartFrame) and (the frame <= myEndFrame) then
  77.     elapsedFrames = the frame - myStartFrame + 1
  78.     memberRect = myTransitionMember.rect
  79.     case direction of
  80.       "left to right", "right to left":
  81.         totalOffset = myTransitionMask.width - memberRect.width
  82.         currentOffset = totalOffset * elapsedFrames / softWipeDuration
  83.         if direction = "right to left" then
  84.           currentMaskRect = offset(memberRect, currentOffset, 0)
  85.         else
  86.           currentMaskRect = offset(memberRect, totalOffset - currentOffset, 0)
  87.         end if
  88.       "top to bottom", "bottom to top":
  89.         totalOffset = myTransitionMask.height - memberRect.height
  90.         currentOffset = totalOffset * elapsedFrames / softWipeDuration
  91.         if direction = "bottom to top" then
  92.           currentMaskRect = offset(memberRect, 0, currentOffset)
  93.         else
  94.           currentMaskRect = offset(memberRect, 0, totalOffset - currentOffset)
  95.         end if
  96.     end case
  97.     myAlphaMask.copyPixels(myOriginalAlpha, myOriginalAlpha.rect, myOriginalAlpha.rect)
  98.     myAlphaMask.copyPixels(myTransitionMask, memberRect, currentMaskRect, [#ink: #lightest])
  99.     myTransitionMember.image.setAlpha(myAlphaMask)
  100.     myTransitionMember.image.useAlpha = 1
  101.     mySprite.member = myTransitionMember
  102.   else
  103.     mySprite.member = myOriginalMember
  104.   end if
  105. end
  106.  
  107. on makeBlendRL me
  108.   blendLine = image(256, 1, 8, 0, #grayscale)
  109.   repeat with i = 0 to 255
  110.     blendLine.setPixel(i, 0, i)
  111.   end repeat
  112.   return blendLine
  113. end
  114.  
  115. on makeBlendBoxRL me, boxWidth, boxHeight
  116.   blendBox = image(boxWidth, boxHeight, 8, 0, #grayscale)
  117.   blendBox.copyPixels(me.makeBlendRL(), blendBox.rect, rect(0, 0, 256, 1))
  118.   return blendBox
  119. end
  120.  
  121. on makeBlendBoxLR me, boxWidth, boxHeight
  122.   blendBox = image(boxWidth, boxHeight, 8, 0, #grayscale)
  123.   blendBox.copyPixels(me.makeBlendBoxRL(boxWidth, boxHeight), [point(boxWidth, 0), point(0, 0), point(0, boxHeight), point(boxWidth, boxHeight)], rect(0, 0, boxWidth, boxHeight))
  124.   return blendBox
  125. end
  126.  
  127. on makeSharpRL me
  128.   sharpLine = image(2, 1, 8, 0, #grayscale)
  129.   sharpLine.setPixel(0, 0, 0)
  130.   sharpLine.setPixel(1, 0, 255)
  131.   return sharpLine
  132. end
  133.  
  134. on makeSharpBoxRL me, boxWidth, boxHeight
  135.   sharpBox = image(boxWidth, boxHeight, 8, 0, #grayscale)
  136.   sharpBox.copyPixels(me.makeSharpRL(), sharpBox.rect, rect(0, 0, 2, 1))
  137.   return sharpBox
  138. end
  139.  
  140. on makeSharpBoxLR me, boxWidth, boxHeight
  141.   sharpBox = image(boxWidth, boxHeight, 8, 0, #grayscale)
  142.   sharpBox.copyPixels(me.makeSharpBoxRL(boxWidth, boxHeight), [point(boxWidth, 0), point(0, 0), point(0, boxHeight), point(boxWidth, boxHeight)], rect(0, 0, boxWidth, boxHeight))
  143.   return sharpBox
  144. end
  145.  
  146. on makeSharpBoxTB me, boxWidth, boxHeight
  147.   sharpBox = image(boxWidth, boxHeight, 8, 0, #grayscale)
  148.   sharpBox.copyPixels(me.makeSharpRL(), [point(boxWidth, 0), point(boxWidth, boxHeight), point(0, boxHeight), point(0, 0)], rect(0, 0, 2, 1))
  149.   return sharpBox
  150. end
  151.  
  152. on isOKToAttach me, aSpriteType, aSpriteNum
  153.   isOK = 0
  154.   case aSpriteType of
  155.     #graphic:
  156.       case sprite(aSpriteNum).member.type of
  157.         #bitmap, #flash, #vectorShape:
  158.           isOK = 1
  159.         #text:
  160.           if sprite(aSpriteNum).member.displayMode = #modeNormal then
  161.             isOK = 1
  162.           end if
  163.       end case
  164.   end case
  165.   return isOK
  166. end
  167.  
  168. on getPropertyDescriptionList me
  169.   props = [:]
  170.   props[#appearWhen] = [#comment: "When transition appears:", #format: #string, #default: "beginning of sprite", #range: ["beginning of sprite", "end of sprite"]]
  171.   firstFrame = sprite(the currentSpriteNum).startFrame
  172.   endFrame = sprite(the currentSpriteNum).endFrame
  173.   maxLength = endFrame - firstFrame + 1
  174.   props[#softWipeDuration] = [#comment: "Duration:", #format: #integer, #default: min(maxLength, 10), #range: [#min: 1, #max: maxLength]]
  175.   props[#direction] = [#comment: "Direction:", #format: #string, #default: "left to right", #range: ["left to right", "right to left", "bottom to top", "top to bottom"]]
  176.   minDim = min(sprite(the currentSpriteNum).member.width, sprite(the currentSpriteNum).member.height)
  177.   props[#softWipeWidth] = [#comment: "Blend Width:", #format: #integer, #default: 15, #range: [#min: 2, #max: minDim]]
  178.   return props
  179. end
  180.  
  181. on getBehaviorTooltip
  182.   return "Creates a transition where the sprite appears on or is removed from the stage with a blended edge wipe."
  183. end
  184.  
  185. on getBehaviorDescription
  186.   return "SOFT-EDGED WIPE TRANSITION" & RETURN & RETURN & "Drop this behavior onto a sprite to create an animation of the sprite sppearing on or disappearing from the stage with a blend ranging from completely transparent to fully opaque." & RETURN & RETURN & "Select when the transition will take effect: 'start' makes the sprite move onto the stage beginning at its first frame, 'end' moves it off at the end of its span. " & "The duration controls the number of frames over which the transition occurs. " & "Direction controls the movement of the sprite. " & "The width of the transition area from transparent to opaque is controlled by the setting for Blend width." & RETURN & RETURN & "When this transition is used during authoring, and the movie is stopped the cast member it uses for the transition effect may not be erased." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "bitmaps and text" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* When transition appears - controls whether sprite moves on or off the stage" & RETURN & "* Duration - number of frames for the transition to take place" & RETURN & "* Direction - movement of sprite onto or off of the stage" & RETURN & "* Blend width - width of blend in pixels"
  187. end
  188.